<?php



/**
 * BerkeleyDb interface 
 *
 * @author chernser
 */
class BerkeleyDb {

    private $itsTables = array();
    private $itsSuffix = './';

    public function BerkeleyDb($suffix) {
        if ($suffix != null) {
           $this->itsSuffix = $suffix;
        }
    }

    public function createTable($name) {
        $handler = dba_open($this->itsSuffix."/".$name, "c");

        if ($handler != false) {
            $this->itsTables[$name] = $handler;
        } else {
            return false;
        }

        return true;
    }

    public function setKeyValue($tableName, $keyName, $value) {
        if (isset ($this->itsTables[$tableName])) {
            dba_insert($keyName, $value, $this->itsTables[$tableName]);
        }
    }

    public function getkeyValue($tableName, $keyName) {
        if (isset ($this->itsTables[$tableName])) {
            return dba_fetch($keyName, $this->itsTables[$tableName]);
        }

        return null;
    }

}
?>
